package com.cskaoyan.demo1.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.text.SimpleDateFormat;

public class JacksonUtil {

    private static ObjectMapper objectMapper =new ObjectMapper();
    static {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        objectMapper.setDateFormat(dateFormat);
    }

    public static <T> T parse(String josnStr,Class<T> clazz) throws JsonProcessingException {
        return objectMapper.readValue(josnStr,clazz);
    }

    public static String toJson(Object object) throws JsonProcessingException {
        return objectMapper.writeValueAsString(object);
    }
}
